home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / desktop / bmp2bgi.zip / BMP2BGI1.C < prev    next >
C/C++ Source or Header  |  1991-05-25  |  2KB  |  57 lines

  1. //////////////////////////////////////////////////////////////////////////
  2. // AccessBMP(char *Filename)
  3. //             This routine opens the BMP file and checks to see if it's
  4. //             okay to use.  At present, BMP files must be:
  5. //                  16-Color & Uncompressed.
  6. //             Will warn if the image is too big for the default video 
  7. //             mode.  BMP file structures should be defined as global 
  8. //             in the calling routine.
  9. //////////////////////////////////////////////////////////////////////////
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <graphics.h>
  14. #include "bmp.h"
  15.  
  16. extern BITMAPFILEHEADER BMPHeader;
  17. extern BITMAPINFOHEADER BMPInfo;
  18.  
  19.  
  20. int AccessBMP(char *BMPFile)
  21. {
  22.         FILE *Fn;
  23.         int gdriver=DETECT, gmode, errorcode=BMP_OK, maxx, maxy;
  24.  
  25.  
  26.         Fn = fopen(BMPFile,"rb");               // Open up BMP image file     
  27.                                                    
  28.                                                 // Read in BMP header
  29.         fread(&BMPHeader,sizeof(BMPHeader),1,Fn);
  30.         fread(&BMPInfo,sizeof(BMPInfo),1,Fn);
  31.         fclose(Fn);
  32.  
  33.                                                 // register a driver that was added into graphics.lib 
  34.         registerfarbgidriver(EGAVGA_driver_far);
  35.  
  36.  
  37.                                                 // initialize graphics and check status 
  38.         initgraph(&gdriver, &gmode, "");
  39.         maxx = getmaxx();
  40.         maxy = getmaxy();
  41.                                                 // Set Error codes, if need be
  42.         if (graphresult() != grOk) errorcode = BMP_BadDriver;
  43.         closegraph();
  44.  
  45.                                                 // Error: Image is too big for video card
  46.         if ((BMPInfo.biWidth+1 >= maxx) || (BMPInfo.biHeight+1 >= maxy)) errorcode = BMP_TooBig;
  47.  
  48.                                                 // Error: only 16-color BMPs can be processed               
  49.         if (BMPInfo.biBitCount != 4) errorcode = BMP_WrongVideo;
  50.  
  51.                                                 // Error: image was compressed 
  52.         if (BMPInfo.biCompression != 0) errorcode = BMP_Compression;
  53.  
  54.         return(errorcode);
  55. }
  56.  
  57.